<template>
	<view class="content">
		<bb-nav type="bbsearch" >
		</bb-nav>
		<view style="margin-top: 20upx;">
			<zzx-tabs :items="items" :cur="cur" @clickItem="Item" ref="mytabs">
			</zzx-tabs>
		</view>
		
		<view style="margin-top: 20upx;color:#999999;font-size: 24upx;height: 260upx;">
			<!--  一  -->
			<view v-show="cur === 0">
				<template v-if="discussPosts.length > 0">
					<main-notiList :info="discussPosts"></main-notiList>
				</template>
				<template v-else>
					<view class="notiBlank">
						<uni-icons type="minus" size="50"></uni-icons>
						无通知
					</view>
				</template>
			</view>
			
			<!--  二  -->
			<view v-show="cur === 1">
				<!-- <template v-if="getInfo(info,1).length > 0">
					<main-notiList :info="getInfo(info,1)"></main-notiList>
				</template>
				<template v-else>
					<view class="notiBlank">
						<uni-icons type="minus" size="50"></uni-icons>
						无通知
					</view>
				</template> -->
			</view>

<!-- 三 -->
			<view v-show="cur === 2">
			</view>
		</view>
		<!--   <view class="">
	            <button type="primary" @click="setMydot">设置dot</button>
	             <button type="default" @click="removeMydot">移除dot</button>
	        </view> -->
	</view>
</template>

<script>
	import zzxTabs from "@/components/HomePage/zzx-tabs/zzx-tabs.vue"
	import bbNav from "@/components/Custom/bb-nav/bb-nav.vue"
	import {
		handleError
	} from "vue";


	export default {
		components: {
			zzxTabs,
			bbNav,			
		},
		data() {
			return {
				items: ['最新', '收藏', '紧急'],
				cur: 0,
				info: [],
				discussPosts: [],
				searchValue: '123123',
				
				current: 1,
				limit: 10
			};

		},
		// 生命周期函数：页面加载时执行
		onLoad() {
			this.getDiscuss()
			 // uni.setTabBarBadge({
			 //      index: 2, // 对应 tabBar 的索引，从 0 开始计算
			 //      text: '99+' // 显示的文本，可以是数字或字符串
			 //    })
			
			this.test()
		},

		// 下拉刷新时执行
		onPullDownRefresh() {
			this.getDiscuss()
		},
		computed: {

		},

		methods: {
			Item(e) {
				if (this.cur !== e.currentIndex) {
					this.cur = e.currentIndex;
				}
			},
			setMydot() {
				this.$refs.mytabs.setDot(1)
			},
			removeMydot() {
				this.$refs.mytabs.removeDot(1);
			},
			// 每个页面根据priority获取对应的内容
			getInfo(infos, priority) {
				var newinfos = []
				if (priority == 0) {
					return infos
				}

				for (var info of infos) {
					if (info.priority == priority) {
						newinfos.push(info)
					}
				}
				return newinfos
			},
			test() {
				if (uni.getStorageSync('ticket')==""){
					uni.showLoading({
						title: '还未登录'
					})
					setTimeout(function() {
						uni.hideLoading();
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}, 3000)
				}
			},
			getDiscuss(){
				const url = `/api/discuss/detail/all?current=${this.current}&limit=${this.limit}&orderMode=0`
				this.$http({
					url: url,
					method: 'GET',
					data: {},
					header: {
						'ticket': uni.getStorageSync('ticket')
					}
				}).then(res => {
					console.log(res.data.data.discussPosts)
					this.$data.discussPosts = res.data.data.discussPosts
				})
			}
		}
	}
</script>

<style>
	.bb-top{
		height: 44px;
	}
	.notiBlank {
		/* border: 1px deeppink solid; */
		display: flex;
		flex-direction: column;
		align-items: center;
		line-height: 35px;
		margin-top: 100rpx;
	}
</style>